package springdb.springdb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import springdb.springdb.bean.User;
import springdb.springdb.repository.UserRepository;

import java.util.Optional;

/**
 * @Auther: luzhanshi
 * @Date: 2021/3/6 - 03 - 06 - 10:13 
 * @Description: springdb.springdb.controller
 * @version: 1.0
 */
@RestController
public class UserController {
@Autowired
    UserRepository userRepository;
    @GetMapping("/user/{id}")
    public Optional getUserById(@PathVariable(name = "id") Integer id) {
        Optional<User> user = userRepository.findById(id);

        return user;
    }
@GetMapping("/user")
    public User insertUser(User user){

    User user1 = userRepository.save(user);
    return user1;
}
}
